#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
char s[100100];
int len;
int nt[100100];
int vis[100100];
void getnt()
{
	nt[0]=-1;
	int i = 0;
	int t = -1;
	while(i<len)
	{
		if(t==-1||s[i]==s[t])
		{
			i++;
			t++;
			nt[i]=t;
		}
		else t = nt[t];
	}
}
int main()
{
	while(scanf("%s",s)!=EOF)
	{
		memset(vis,0,sizeof(vis));
		len = strlen(s);
		getnt();
		//printf("%d\n",nt[len]);
		if(len<3)
		{
			printf("Just a legend\n");
		}
		else
		{
			for(int i = 1;i<len;i++)
			{
				//printf("***%d\n",nt[i]);
				vis[nt[i]]=1;
			}
			int i = nt[len];
			while(!vis[i]&&i)
			{
			
				i = nt[i];
			}
			//printf("+++%d\n",i);
			if(i!=0)
			{
				for(int j = 0;j<i;j++)
				{
					printf("%c",s[j]);
				}
				printf("\n");
			}
			else printf("Just a legend\n");
		}
	}
}
